# url = "https://ke-image.ljcdn.com/hdic-frame/standard_477d6cbd-9d4f-42cf-b819-4082813fc63a.png.1440x1080.jpg?from=ke.com"
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_477d6cbd-9d4f-42cf-b819-4082813fc63a.png.1000x750.jpg?from=ke.com"
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_943136ed-4198-4540-8634-77f23087d59e.png!m_fill,w_1000,h_750,l_bk,f_jpg,ls_50?from=ke.com"
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_071a6609-21e3-402b-8cf4-6de40a9355fc.png!m_fill,w_1000,h_750,l_bk,f_jpg,ls_50?from=ke.com"
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_596b67f5-1b17-4ac4-8275-88440786239c.png!m_fill,w_1000,h_750,l_bk,f_jpg,ls_50?from=ke.com"
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_302bbb48-95dd-4a43-b86d-4bfb6b7d45b0.png!m_fill,w_1000,h_750,l_bk,f_jpg,ls_50?from=ke.com"
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_1a24543b-76d2-4582-8321-9ea074543cdb.png!m_fill,w_1000,h_750,l_bk,f_jpg,ls_50?from=ke.com"
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_f8854f11-98b8-4d34-b835-36984d36bb40.png!m_fill,w_1000,h_750,l_bk,f_jpg,ls_50?from=ke.com"

#url = "https://ke-image.ljcdn.com/hdic-frame/standard_70f0fd6c-c9f0-418a-905a-3dc04c714ec4.png!m_fill,w_1000,h_750,l_bk,f_jpg,ls_50?from=ke.com"
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_5b78d8fa-f48c-4040-8b7e-b2953d0121d2.png!m_fill,w_710,h_400,l_bk,f_jpg,ls_50?from=ke.com"
# 垂直交叉太小，水平对齐设置*2完美解决
# url = "http://ke-image.ljcdn.com/hdic-frame/standard_18125c34-a482-48d1-bfd2-da1808ea979d.png.1440x1080.jpg?from=ke.com"
# url = "http://ke-image.ljcdn.com/hdic-frame/standard_d470f1c5-bcd7-4047-9aa6-759abab61fee.png.1440x1080.jpg?from=ke.com"
# url = "http://ke-image.ljcdn.com/hdic-frame/standard_45872acf-107e-494c-9820-a123a013c73a.png.1440x1080.jpg?from=ke.com"
# 垂直交叉太大，会将门封闭
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_6adfce13-91bb-4bcc-9bd2-d363d856e965.png!m_fill,w_1000,h_750,l_bk,f_jpg,ls_50?from=ke.com"
# url = "http://ke-image.ljcdn.com/hdic-frame/standard_e692794f-0e47-4375-86e9-cf6ada133055.png.1440x1080.jpg?from=ke.com"
#  合成方案少墙
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_f5c7339a-9162-4596-98c9-292e54b6cd6d.png.1440x1080.jpg?from=ke.com"

# url = "https://ke-image.ljcdn.com/hdic-frame/standard_e520a0b7-4acb-4a0f-a7f6-caf64a8781cd.png.1440x1080.jpg?from=ke.com"
# url = "http://ke-image.ljcdn.com/hdic-frame/standard_87022659-4ed1-4275-8f5c-575cfb745629.png.1440x1080.jpg?from=ke.com"
# url = "http://ke-image.ljcdn.com/hdic-frame/standard_16173bcf-da62-4afb-9cb6-2bba6e4267bd.png.1440x1080.jpg?from=ke.com"
# 终极测试图-多一点墙体 提取墙体，移除门 阈值为10可以解决
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_efa4eb78-ceec-485d-ab1c-cb990c9c7070.png!m_fill,w_1000,h_750,l_bk,f_jpg,ls_50?from=ke.com"

# url = "https://ke-image.ljcdn.com/hdic-frame/standard_4ddd21c3-48b3-42db-a5d0-e2d167cf3606.png.1440x1080.jpg?from=ke.com"
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_1590e803-044e-4058-9728-0db7ebacff14.png.1440x1080.jpg?from=ke.com"
# url = "http://ke-image.ljcdn.com/hdic-frame/standard_21150bc7-f3e6-4b84-8ea2-aad12dea9492.png.1440x1080.jpg?from=ke.com"
# url = "https://ke-image.ljcdn.com/hdic-frame/standard_b1fef136-7517-4468-97de-59cd0f35c80c.png.1440x1080.jpg?from=ke.com"
url = "http://ke-image.ljcdn.com/hdic-frame/standard_45872acf-107e-494c-9820-a123a013c73a.png.1440x1080.jpg?from=ke.com"
# 门多余的墙干掉
# url = "http://ke-image.ljcdn.com/hdic-frame/standard_e520a0b7-4acb-4a0f-a7f6-caf64a8781cd.png.1440x1080.jpg?from=ke.com"
# 测试替换
url = "http://ke-image.ljcdn.com/hdic-frame/standard_bc398728-0393-4e00-b679-fa773ac23234.png.1440x1080.jpg?from=ke.com"


import os
import sys
package_dir =os.path.abspath('').replace("/","")
sys.path.insert(0, package_dir)

# 获取线框图坐标点
from WireFrames import *
wireFrames_fun = WireFrames()
alldata_result = wireFrames_fun.process_urls(url)
# alldata_result = []
# print(alldata_result)

# # 获取原始图比例
# 获取比例信息 [min_x,min_y,max_x,max_y],[w,h]
from UrlOcr import UrlOcr
urlOcr_fun = UrlOcr()
urlOcr_result = urlOcr_fun.process_urls(url)
# print("==============")
#print(urlOcr_result)

# 获取比例信息 radio_wall
from RadioWall import RadioWall
radioWall_fun = RadioWall()
radio_wall_result = radioWall_fun.process_and_display(alldata_result[0],urlOcr_result)
# print("==============")
#print(radio_wall_result)

# radio_wall_result = 24.6767
# todo:容错处理
# 标记标尺比例，是否正常
radio_wall_flag = True
if radio_wall_result<20 or radio_wall_result>28:
    radio_wall_flag = False
    radio_wall_result = 24.6767
alldata = alldata_result[0] + alldata_result[1]
alldata2 = alldata_result[2]

from FloorplanImageDataConverter import FloorplanImageDataConverter

fl_img_dc = FloorplanImageDataConverter()
x_data,y_data, move_xy = fl_img_dc.run(alldata, radio_wall_result,alldata2)

# 入参：url
# 1.获取房间的真实坐标x1,y1
# 2.根据原图与线框图的px宽度比例，换算处理 x2,y2
# 3.移动 x-move_xy[0],y-move_xy[1] -> x,y
# 返回：[{"name":"客厅","point":[x,y]}]
extracted_values = []
if radio_wall_flag:
    # 标尺比例正常才进行房间标记
    orgimg_data = radioWall_fun.calculate_max_min(alldata_result[0])
    #  线框图的宽/原图的宽
    img_radio = (orgimg_data[2]-orgimg_data[0])/(urlOcr_result[4][2] - urlOcr_result[4][0])
    from FurnitureOcr import FurnitureOcr
    FurnitureOcr_fun = FurnitureOcr()
    extracted_values = FurnitureOcr_fun.process_urls(url,img_radio,move_xy,orgimg_data,radio_wall_result,alldata_result[0])


from KeFloorplanConverter import KeFloorplanConverter

keFloorplanConverter = KeFloorplanConverter()
mangoDict = keFloorplanConverter.run((x_data+y_data),extracted_values)
print(json.dumps(mangoDict, ensure_ascii=False))